home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 193_01 / deff3.c < prev    next >
Text File  |  1985-11-13  |  18KB  |  504 lines

  1. /*-----------------------------------------------------------------*/
  2. /*  LIBRARY FUNCTIONS  ==>  written by Phil Cogar                  */
  3. /*  For BDS C under CP/M 2.2 using the "BDOS" Function             */
  4. /*                                                                 */
  5. /*  This file contains the following functions -                   */
  6. /*                                                                 */
  7. /*       CGET                CPUT           DIRECTC                */
  8. /*       CLRSCREEN           LISTC          GET_IOBYTE             */
  9. /*       SET_IOBYTE          PRT_STR        READ_STR               */
  10. /*       CON_STAT            GET_CPM        RESET_DSK              */
  11. /*       SELECT_DSK          OPEN_FILE      CLOSE_FILE             */
  12. /*       SEARCH_FIRST        SEARCH_NEXT    CREATE_FILE            */
  13. /*       ERASE_FILE          READ_SEQ_SEC   WRITE_SEQ_SEC          */
  14. /*       GET_DEFAULT         SET_DMA        MAKE_RO                */
  15. /*       SET_ATTRIBUTES      USER_ID        BITCOUNT               */
  16. /*       BINARY              SHELL_SORT     REVERSE                */
  17. /*       ITOA                INDEX          PRINT_DEC              */
  18. /*       SWAP_POINTERS       ISALNUM                               */
  19. /*                                                                 */
  20. /*  all of which are described in DEFF3.TXT and are                */
  21. /*  contained in the linking file  ==>  DEFF3.CRL                  */
  22. /*  Copyright 1986 - Cogar Computer Services Pty. Ltd.             */
  23. /*-----------------------------------------------------------------*/
  24. #include "pec.h"    /* definitions required                    */
  25. /*=================================================================*/
  26. /*            CGET                                                 */
  27. /*  Read Console Byte  ==>  CP/M Function No. 1                    */
  28. /*  Note will read any BYTE value from the console                 */
  29.  
  30. cget()
  31. {
  32.     bdos(READ,0);
  33. }
  34. /*-----------------------------------------------------------------*/
  35. /*            CPUT                                                 */
  36. /*  Write Console Byte  ==> CP/M Function No. 2                    */
  37. /*  Note will send any BYTE value to the console                   */
  38.  
  39. cput(c)
  40. int c;
  41. {
  42.     bdos(WRITE,c);
  43. }
  44. /*-----------------------------------------------------------------*/
  45. /*            CLRSCREEN                                            */
  46. /*  Clear screen function for Hazeltine Esprit terminal            */
  47.  
  48. clrscreen()
  49. {
  50.     cput(126);
  51.     cput(28);
  52. }
  53. /*-----------------------------------------------------------------*/
  54. /*            LISTC                                                */
  55. /*  List byte to line printer                                      */
  56.  
  57. listc(c)
  58. int c;
  59. {
  60.  
  61.     bdos(LIST, c);
  62. }
  63. /*-----------------------------------------------------------------*/
  64. /*            DIRECTC                                              */
  65. /*  Use direct console IN/OUT  ==>  CP/M function No. 6            */
  66. /*  Note:     DUTY = IN = 0FFH                                     */
  67. /*                 = OUT = character to be printed to screen       */
  68. /*  Returns either the input character or Reg. A = 0               */
  69. /*-----------------------------------------------------------------*/
  70.  
  71. #define    IN 255    /* Character in function */
  72.  
  73. directc(DUTY)
  74. int DUTY;
  75. {
  76.     bdos(DCIO,DUTY);
  77. }
  78. /*-----------------------------------------------------------------*/
  79. /*            GET_IOBYTE                                           */
  80. /*  Get IOBYTE setting                                             */
  81. /*  Returns the current IOBYTE setting                             */
  82. /*-----------------------------------------------------------------*/
  83.  
  84. get_iobyte()
  85. {
  86.     bdos(IOBYTE,0);
  87. }
  88. /*-----------------------------------------------------------------*/
  89. /*            SET_IOBYTE                                           */
  90. /*  Sets the IOBYTE                                                */
  91. /*  Doesn't return anything                                        */
  92. /*-----------------------------------------------------------------*/
  93.  
  94. set_iobyte(IOB)
  95. short IOB;    /* new IOBYTE setting */
  96. {
  97.     bdos(SET_IOBYTE,IOB);
  98. }
  99. /*-----------------------------------------------------------------*/
  100. /*            PRT_STR                                              */
  101. /*  Print a "$" terminated string to the console                   */
  102. /*  Doesn't return anything                                        */
  103. /*-----------------------------------------------------------------*/
  104.  
  105. prt_str(BUFF)
  106. char *BUFF;    /* pointer to string buffer */
  107. {
  108.     bdos(PRT_STRING,BUFF);
  109. }
  110. /*-----------------------------------------------------------------*/
  111. /*            READ_STR                                             */
  112. /*  Read a "RETURN" terminated string from the console             */
  113. /*  Note:     The CR doesn't form part of the string.   As written */
  114. /*  ----      this function terminates the string with a null.     */
  115. /*-----------------------------------------------------------------*/
  116.  
  117. #define BUFF_LEN    134    /* maximum number of characters */
  118.  
  119. read_str(BUFF)
  120. short *BUFF;
  121. {
  122.     short n;
  123.     for(n = 0; n <= BUFF_LEN; n++)
  124.     {
  125.         BUFF[n] = '\0';    /* Initialise string with NULL's */
  126.     }
  127.     
  128.     BUFF[0] = BUFF_LEN;    /* must tell CP/M buffer size */
  129.  
  130.     bdos(READ_STRING,BUFF);
  131. }
  132. /*-----------------------------------------------------------------*/
  133. /*            CON_STAT                                             */
  134. /*  Read the console status  ==>  CP/M Function No. 11             */
  135. /*  Returns NULL if no character waiting, else returns 0FFH        */
  136. /*-----------------------------------------------------------------*/
  137.  
  138. con_stat()
  139. {
  140.     bdos(CON_STATUS,0);
  141. }
  142. /*-----------------------------------------------------------------*/
  143. /*            GET_CPM                                              */
  144. /*  Get CP/M Version Number                                        */
  145. /*  Number is returned in HL with the details -                    */
  146. /*                                                                 */
  147. /*     H = 00H for CP/M  or H = 01H for MP/M                       */
  148. /*     L = 00H for all releases prior to 2.0                       */
  149. /*     L = 20H for release 2.0, 21H for release 2.1, 22H for       */
  150. /*         release 2.2, and so on.                                 */
  151. /*-----------------------------------------------------------------*/
  152.  
  153. get_cpm()
  154. {
  155.     bdos(CPM_NUM,0);
  156. }
  157. /*-----------------------------------------------------------------*/
  158. /*            RESET_DSK                                            */
  159. /*  Reset the disk system                                          */
  160. /*  Typically used after a disk is changed                         */
  161. /*  Does not return anything                                       */
  162. /*-----------------------------------------------------------------*/
  163.  
  164. reset_dsk()
  165. {
  166.     bdos(RESET,0);
  167. }
  168. /*-----------------------------------------------------------------*/
  169. /*            SELECT_DSK                                           */
  170. /*  Select logical disk  ==>  CP/M Function No. 14                 */
  171. /*  This makes the nominated disk the default disk                 */
  172. /*  Note:     Drive A = 00H                                        */
  173. /*  ----      Drive B = 01H, and so on                             */
  174. /*-----------------------------------------------------------------*/
  175.  
  176. select_dsk(DISK)
  177. short DISK;
  178. {
  179.     toupper(DISK);    /* make this upper case */
  180.     DISK = DISK - 66; /* convert to A = 0, B = 1, etc */
  181.  
  182.     bdos(LOGICAL,DISK);
  183. }
  184. /*-----------------------------------------------------------------*/
  185. /*            OPEN_FILE                                            */
  186. /*  Open a file  ==>  CP/M Function No. 15                         */
  187. /*  To use this you must have previously formulated a File         */
  188. /*  Control Block (FCB) using setfcb(fcbaddr, filename)            */
  189. /*  Returns the Directory code in Register A, or 0FFH if it failed */
  190. /*  Note particularly the nominated FCB must be